//
//  BaseViewController.m
//  快读
//
//  Created by wangning on 15/8/31.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "BaseViewController.h"
#import "PersonViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //页面跳转不卡
        self.view.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

//个性化配置tabbaItem,根据我们所加载的页面
- (void)configTabbarItemTabbarItemMode:(mTabbarItemMode)tabbarItemMode
{
    switch (tabbarItemMode) {
        case mTabbarItemModeBookShelf:
            [self configTabbarItemWithTitle:nil normalImage:@"BookShelf_1" selectedImg:@"BookShelf_2"];
            break;
        case mTabbarItemModeBookCity:
            [self configTabbarItemWithTitle:nil normalImage:@"BookCity_1" selectedImg:@"BookCity_2"];
            break;
        case mTabbarItemModeBookList:
            [self configTabbarItemWithTitle:nil normalImage:@"BookList_1" selectedImg:@"BookList_2"];
            break;
        case mTabbarItemModeBookBar:
            [self configTabbarItemWithTitle:nil normalImage:@"BookBar_1" selectedImg:@"BookBar_2"];
            break;
        case mTabbarItemModeAmusement:
            [self configTabbarItemWithTitle:nil normalImage:@"Amusement_1" selectedImg:@"Amusement_2"];
            break;
            
        default:
            break;
    }
}

//为不同的界面配置tabbarItem
- (void)configTabbarItemWithTitle:(NSString *)title normalImage:(NSString *)normalImage selectedImg:(NSString *)selecedImg{
    
    UIImage *normalTabImg = [[UIImage imageNamed:normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//使用自定义的图片
    UIImage *selectedTabImg = [[UIImage imageNamed:selecedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:nil image:normalTabImg selectedImage:selectedTabImg];
    self.tabBarItem = tabbarItem;
    
}

//初始化导航栏的同时，添加返回按钮，设置title
- (void)configTitleAndBackItem:(NSString *)title{
    self.title = title;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"Amusement_1"] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"Amusement_2"] forState:UIControlStateHighlighted];
    backBtn.frame = CGRectMake(0, 0, 30, 30);
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceItem.width = -10;
    
    [self.navigationItem setLeftBarButtonItems:@[spaceItem,backItem]];
}

- (void)back
{
    PersonViewController *per = [[PersonViewController alloc]init];
    [self.navigationController pushViewController:per animated:YES];
}

@end
